import {VIRTUAL_NODE_TYPE} from "../../../constant";

/**
 * 生成一个新的节点
 * @param {VNode} vnode
 */
export function createElement (vnode) {
    let element = null;
    if (!vnode.isComponent) {
        switch (vnode.nodeType) {
            case (VIRTUAL_NODE_TYPE.ELEMENT): {
                element = document.createElement(vnode.tag);
                break;
            }
            case (VIRTUAL_NODE_TYPE.TEXT): {
                element = document.createTextNode(vnode.textContent);
                break;
            }
            case (VIRTUAL_NODE_TYPE.COMMENT): {
                element = document.createComment(vnode.textContent);
                break;
            }
        }
    }
    else {
        element = document.createComment(vnode.tag);
    }
    return element;
}
